package com.fangcang.filter;

import java.io.IOException;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter(urlPatterns= "/mvc/*")
public class DemoFilter implements Filter{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("DemoFilter init");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		Map<String, String[]> datas  = request.getParameterMap();
		if(datas != null && !datas.isEmpty()) {
			for(Map.Entry<String, String[]> data : datas.entrySet()) {
				System.out.println("key=" + data.getKey() + "；value=" + data.getValue()[0]);
			}
		}
		System.out.println(request.getServletContext().getRealPath("/"));
		System.out.println("execute DemoFilter doFilter method");
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		
	}

}
